﻿// Copyright (c) Microsoft. All rights reserved.

using Newtonsoft.Json;

namespace Microsoft.Azure.IoTSolutions.AsaManager.Services.Models
{
    // See https://github.com/Azure/device-telemetry-dotnet/blob/master/WebService/v1/Models/ConditionApiModel.cs
    public class ConditionApiModel
    {
        [JsonProperty("Field")]
        public string Field { get; set; }

        [JsonProperty("Operator")]
        public string Operator { get; set; }

        [JsonProperty("Value")]
        public string Value { get; set; }

        public override bool Equals(object obj)
        {
            if (!(obj is ConditionApiModel x)) return false;

            return string.Equals(this.Field, x.Field)
                   && string.Equals(this.Operator, x.Operator)
                   && string.Equals(this.Value, x.Value);
        }

        /// <summary>Method required when implementing a custom equality logic [CS0659]</summary>
        /// <remarks>Code auto-generated by IDE</remarks>
        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = (this.Field != null ? this.Field.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (this.Operator != null ? this.Operator.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (this.Value != null ? this.Value.GetHashCode() : 0);
                return hashCode;
            }
        }
    }
}
